import request from "@/utils/request";
import qs from "qs";

// 读取栏目下文章列表
export function getListArticle(data) {
  return request({
    url: "/article/list",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "post",
    data: qs.stringify(data),
  });
}

//文章分类查询状态列表
export function getArticleOption() {
  return request({
    url: "/article/getArticleShowType",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "post",
  });
}

//文章复制
export function articleCopy(data) {
  return request({
    url: "/article/copyArticle",
    headers: {
      "content-type": "application/x-www-form-urlencoded",
      showLoading: true,
    },
    method: "post",
    timeout: 0,

    data: qs.stringify(data),
  });
}
//文章移动
export function articleMove(data) {
  return request({
    url: "/article/moveArticle",
    headers: {
      "content-type": "application/x-www-form-urlencoded",
      showLoading: true,
    },
    method: "post",
    timeout: 0,

    data: qs.stringify(data),
  });
}

//设置文章置顶
export function articleSetTop(data) {
  return request({
    url: "/article/setTop",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "post",
    timeout: 0,
    data: qs.stringify(data),
  });
}

//设置文章弹出
export function articleSetJump(data) {
  return request({
    url: "/article/setJump",
    headers: {
      "content-type": "application/x-www-form-urlencoded",
      showLoading: true,
    },
    method: "post",
    timeout: 0,

    data: qs.stringify(data),
  });
}

//删除文章
export function articleRemove(data) {
  return request({
    url: "/article/remove",
    headers: {
      "content-type": "application/x-www-form-urlencoded",
      showLoading: true,
    },
    method: "post",
    timeout: 0,
    data: qs.stringify(data),
  });
}

//文章上移一位
export function moveUpArticle(data) {
  return request({
    url: "/article/moveUpArticle",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "post",
    data: qs.stringify(data),
  });
}
//文章下移一位
export function moveDownArticle(data) {
  return request({
    url: "/article/moveDownArticle",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "post",
    data: qs.stringify(data),
  });
}

//获取编辑文章时的文章内容
export function getArticleInfo(data) {
  return request({
    url: "/article/getArticleInfo",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "post",
    data: qs.stringify(data),
  });
}

//新增文章
export function articleStatusList(data, params) {
  return request({
    url: "/article/getArticleStatus",
    method: "post",
    headers: { showLoading: true },
    timeout: 0,
    data: data,
    params: params,
  });
}

//新增文章
export function addArticle(data, params) {
  return request({
    url: "/article/addArticle",
    method: "post",
    headers: { showLoading: true },
    timeout: 0,
    data: data,
    params: params,
  });
}

//编辑处理（更新）文章
export function editArticle(data, params) {
  return request({
    url: "/article/editArticle",
    headers: { showLoading: true },
    timeout: 0,
    method: "post",
    data: data,
    params: params,
  });
}

//读取用户  编辑文章   页面的按钮权限
export function getButtonForEdit(data) {
  return request({
    url: "/article/getButtonForEdit",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "post",
    data: qs.stringify(data),
  });
}

//读取用户    文章列表   页面的按钮权限
export function getButtonForAdd(data) {
  return request({
    url: "/article/getButtonForAdd",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "post",
    data: qs.stringify(data),
  });
}

// 读取文章审核记录
export function getArticleWorkFlowList(data) {
  return request({
    url: "/article/getArticleWorkFlowList",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "post",
    data: qs.stringify(data),
  });
}
// 验证文章标题是否在栏目下已存在
export function validateHeader(data) {
  return request({
    url: "/article/validateHeader",
    headers: {
      "content-type": "application/x-www-form-urlencoded",
      showLoading: false,
    },
    method: "post",
    data: qs.stringify(data),
  });
}

// 读取栏目下相同名称的文章列表
export function getIsonymArticleList(data) {
  return request({
    url: "/article/getIsonymArticleList",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "post",
    data: qs.stringify(data),
  });
}

// 通过子部门 读取 父部门信息
export function getParentDep(params) {
  return request({
    url: "/department/getParent",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "GET",
    params: params,
  });
}

// 读取栏目已配置流程信息
export function workFlowConfig(channelId) {
  return request({
    url: `/channel/workFlowConfig/${channelId}`,
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "POST",
  });
}
// 读取流程定义中的可选择人员
export function workflowUserList(data) {
  return request({
    url: `/channel/workflowUserList`,
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "POST",
    data: qs.stringify(data),
  });
}

// 分享流程定义给其它栏目
export function shareWFToOtherChannel(data) {
  return request({
    url: `/channel/shareWFToOtherChannel`,
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "POST",
    data: qs.stringify(data),
  });
}

// 保存流程定义人员
export function saveWorkflowUser(data) {
  return request({
    url: `/channel/saveWorkflowUser`,
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "POST",
    params: data,
    data: qs.stringify(data),
  });
}
//17  保存栏目流程设置
export function saveNewWorkflow(data) {
  return request({
    url: "/channel/saveNewWorkflow",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "post",
    data: qs.stringify(data),
  });
}

//22 删除文章附件、图片、视频
export function deleteArticleFiles(data) {
  return request({
    url: "/article/deleteArticleFiles",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "post",
    data: qs.stringify(data),
  });
}

//08、刷新用户正在查看或编辑文章的状态
export function refreshUserEditStatus(data) {
  return request({
    url: "/article/refreshUserEditStatus",
    headers: {
      "content-type": "application/x-www-form-urlencoded",
      showLoading: false,
    },
    method: "post",
    data: qs.stringify(data),
  });
}

//13、文章分享到其它栏目
export function shareArticle(data) {
  return request({
    url: "/article/shareArticle",
    headers: {
      "content-type": "application/x-www-form-urlencoded",
      showLoading: false,
    },
    method: "post",
    data: qs.stringify(data),
    params: data,
  });
}
//14、移出文章分享信息
export function deleteArticleRelevance(data) {
  return request({
    url: "/article/deleteArticleRelevance",
    headers: {
      "content-type": "application/x-www-form-urlencoded",
      showLoading: false,
    },
    method: "post",
    data: qs.stringify(data),
  });
}

//26、查看文章被分享到的栏目
export function seeArticleSharedChannels(data) {
  return request({
    url: "/article/seeArticleSharedChannels",
    headers: {
      "content-type": "application/x-www-form-urlencoded",
      showLoading: false,
    },
    method: "post",
    data: qs.stringify(data),
  });
}
//  deleteArticleRelevance
export function setArticleSequence(data) {
  return request({
    url: "/article/setArticleSequence",
    headers: {
      "content-type": "application/x-www-form-urlencoded",
      showLoading: false,
    },
    method: "post",
    data: qs.stringify(data),
  });
}

// 27、导出栏目下文章列表
export function exportArticle(data) {
  return request({
    url: "/article/list/export",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    responseType: "blob",
    method: "post",
    data: qs.stringify(data),
  });
}

// 01、读取可以一稿多投的网站列表
export function duplicateSubmissionList(data) {
  return request({
    url: "/duplicateSubmission/site/list",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "post",
    data: qs.stringify(data),
  });
}

//11 获取网站域名
export function getWebDomain(data) {
  return request({
    url: "/useful/getWebDomain",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "post",
    data: qs.stringify(data),
  });
}

//  31、设置文章排序时间字段
export function setArticleSeqTime(data) {
  return request({
    url: "/article/setArticleSeqTime",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "post",
    data: qs.stringify(data),
  });
}

//  32、文章信息缓存接口
export function setArticleCache(data) {
  return request({
    url: "/article/setArticleCache",
    method: "post",
    data: data,
  });
}

// 33、读取文章信息缓存
export function getArticleCache(data) {
  return request({
    url: "/article/getArticleCache",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "post",
    data: qs.stringify(data),
  });
}

//  导出文章流程
export function getArticleWorkFlowExport(data) {
  return request({
    url: "/article/export/workFlow",
    headers: { "content-type": "application/x-www-form-urlencoded" },
    method: "post",
    data: qs.stringify(data),
  });
}

//  导出运城打包下载
export function getPckDown(params) {
  return request({
    url: "/yuncheng/package/download",
    method: "post",
    params,
  });
}

//  手动 上传文件附件  附件排序时加入  暂时不用。 还是自动上传
export function uploadArticleAttr(data, onUpload) {
  return request({
    url: "/common/upload",
    method: "post",
    data: data,
    headers: { "content-type": "multipart/form-data" },
    onUploadProgress: (progressEvent) => {
      //onUploadProgress:   axios文件上传
      console.log("progressEvent: ", progressEvent);
      const complete = parseInt(
        ((progressEvent.loaded / progressEvent.total) * 100) | 0,
        10
      );
      onUpload.onProgress({ percent: complete }); //onProgress()实现进度条
    },
  });
}
